package com.animations;

import com.beans.BirdBean;
import com.beans.RoadBean;
import creator.ui.graphics.Magicanvas;
import creator.ui.graphics.bean.Switch;
import creator.ui.graphics.polaroid.Animation;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ArrayList;

public class RoadAction extends Animation {

  private RoadBean road;
  private int roadX = 0;

  public void loadBean() {
    this.road = new RoadBean();
    getBeans().add(this.road);
  }

  public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.drawImage(
      this.road.getRoad(),
      this.roadX,
      this.road.getRoadY(),
      getMagicanvas()
    );

    g2d.drawImage(
      this.road.getRoad(),
      this.roadX + this.road.getRoadW(),
      this.road.getRoadY(),
      getMagicanvas()
    );
  }

  public synchronized void run() {
    while ((Switch._isContinue()) && (BirdBean._isAlive())) {
      if (this.roadX > 1 - this.road.getRoadW()) this.roadX -=
        1; else this.roadX = 0;
      try {
        Thread.sleep(8L);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      getMagicanvas().repaint();
    }
  }
}
